/**
 * 职位 - 编辑页面
 * @author yuan_rz
 * @date 2019/01/10 11:29
 */
define(function () {

    var self,
        app = win.app,
        doc = document,
        vueData = {
            isAdd: false,
            isDetail: false,
            form: '',
            rules: {
                GWBD001: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWBDACTI: [
                    {required: true, message: '不可为空', trigger: 'change'}
                ],
                GWBDL003: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWBDL004: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ]
            },
            selectOptions:{
                sys_y_n : app.datas_('sys_y_n')
            }
        },
        callObj,
        pageVue,
        moduleName
    ;

    var gwat233Edit = app.Module.extend({
        init: function () {
            self = this;
            self._super({
                _tag: 'gwat233_edit',
            }, win);
        },
        editData: function () {
            app.ajax({
                xurl: 'base/gwat233/editData',
                xdata: vueData.form,
                loading: true,
                okmsg: moduleName + '信息修改成功',
                cb: function (result) {
                    if (result.ok) {
                        //同步更新缓存对应的值
                        // callObj.update(result.xdata);
                        app.pageModule('gwat233').reloadTableCurr();
                        layer.close(layer.index);
                    }
                }
            });
        },
        addData: function () {
            app.ajax({
                xurl: 'base/gwat233/addData',
                xdata: vueData.form,
                loading: true,
                okmsg: moduleName + '信息保存成功',
                cb: function (result) {
                    if (result.ok) {
                        app.pageModule('gwat233').reloadTableCurr();
                        layer.close(layer.index);
                    }
                }
            });
        },
        _call: function (tagData) {
            pageVue.$refs['form'].resetFields();
            moduleName = tagData.moduleName;
            if(tagData.is_detail){
                vueData.isDetail = true;
            }else {
                vueData.isDetail = false;
            }
            if (tagData.is_add) {
                vueData.isAdd = true;
                app.extendUpLow({
                    target: vueData.form,
                    res: {
                        GWBD001: '',
                        GWBDACTI: 'Y',
                        GWBDL003: '',
                        GWBDL004: ''
                    },
                    reset: true
                });
            } else {
                vueData.isAdd = false;
                callObj = tagData.obj;
                app.extendUpLow({
                    target: vueData.form,
                    res: [callObj.data,{
                        oldGWBD001 : callObj.data.GWBD001
                    }],
                    reset: true
                });
            }

        },
        _ready: function () {
            vueData.form = app.fields_(['base_gwat233']);
            pageVue = new Vue({
                el: '#gwat233_edit',
                data: vueData,
                methods: {
                    cancel: function () {
                        layer.close(layer.index);
                    },
                    sure: function () {
                        this.$refs['form'].validate(function (valid) {
                            if (valid) {
                                if (vueData.isAdd) {
                                    self.addData();
                                } else {
                                    self.editData();
                                }
                            }
                        });
                    }
                },
                watch: {
                    'form.GWBD001': function(newValue,oldValue){
                        this.form.GWBDL001 = newValue;
                    }
                },
                created: function () {
                    self._setEleIsReady('gwat233_edit');
                }
            });
        },
        _lazy: function () {
            this._super();
        }
    });

    return new gwat233Edit();

});